package com.hws.leetcode.Day_01_09;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName:leetcode_1629
 * Package:com.hws.leetcode.Day_01_09
 * Description:
 *
 * @ date:2022/1/9 13:18
 * @ author:hws
 */
public class leetcode_1629 {

    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int[] nums = new int[releaseTimes.length];
        nums[0] = releaseTimes[0];
        for (int i = 1; i < releaseTimes.length; i++) {
            nums[i] = releaseTimes[i] - releaseTimes[i - 1];
        }
        int maxIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[maxIndex] < nums[i]) {
                maxIndex = i;
            }
        }
        List<Integer> indexList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == nums[maxIndex]) {
                indexList.add(i);
            }
        }
        char maxChar = 'a';
        for (Integer index : indexList) {
            if (maxChar < keysPressed.charAt(index)) {
                maxChar = keysPressed.charAt(index);
            }
        }
        return maxChar;
    }

    public static void main(String[] args) {
        leetcode_1629 lc = new leetcode_1629();
        int[] nums = new int[]{12,23,36,46,62};
        String keysPressed = "spuda";
        System.out.println(lc.slowestKey(nums, keysPressed));
    }

}
